//
//  NSObjectModelDesc.m
//  ZITHER
//
//  Created by imac on 2018/5/28.
//  Copyright © 2018年 MinesTime. All rights reserved.
//

#import "NSObjectModelDesc.h"
@interface NSObjectModelDesc ()

@property (nonatomic, copy) NSString *output;


@end

@implementation NSObjectModelDesc
- (NSString *)description {
    return [self yy_modelDescription];
}

- (instancetype)initWithDict:(NSDictionary *)dict {
    if (self = [super init]) {
        [self setValuesForKeysWithDictionary:dict];
    }
    NSLog(@"%@",_output);
    return self;
}

- (void)setValue:(id)value forKey:(NSString *)key {
    [super setValue:value forKey:key];
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
    NSString *className = NSStringFromClass([value class]);
    if ([className isEqualToString:@"__NSCFNumber"]) {
        const char * objCType = [((NSNumber*)value) objCType];
        if (strcmp(objCType, @encode(float)) == 0) {
            
            _output = [NSString stringWithFormat:@"%@\n/** */\n@property (nonatomic, assign) float %@;",_output,key];
        }
        
        if (strcmp(objCType, @encode(double))  == 0) {
            
            _output = [NSString stringWithFormat:@"%@\n/** */\n@property (nonatomic, assign) double %@;",_output,key];
        }
        
        if (strcmp(objCType, @encode(int))  == 0) {
            
            _output = [NSString stringWithFormat:@"%@\n/** */\n@property (nonatomic, assign) int %@;",_output,key];
        }
        
        if (strcmp(objCType, @encode(BOOL)) == 0) {
            
            _output = [NSString stringWithFormat:@"%@\n/** */\n@property (nonatomic, assign) BOOL %@;",_output,key];
        }
        
        if (strcmp(objCType, @encode(NSInteger)) == 0) {
            
            _output = [NSString stringWithFormat:@"%@\n/** */\n@property (nonatomic, assign) NSInteger %@;",_output,key];
        }
        
        
    } else if ([className isEqualToString:@"__NSCFString"] || [className isEqualToString:@"NSTaggedPointerString"]) {
        _output = [NSString stringWithFormat:@"%@\n/** */\n@property (nonatomic, copy) NSString *%@;",_output,key];
        
    } else if ([className isEqualToString:@"__NSArrayI"]) {
        _output = [NSString stringWithFormat:@"%@\n/** */\n@property (nonatomic, strong) NSArray *%@;",_output,key];
        
    }
}

@end



